$(document).ready(function() {
    // 当前筛选条件
    let currentFilters = {
        subject: 'all',
        year: 'all',
        grade: 'all'
    };
    
    // 更新文件列表显示
    function updateFileList() {
        $('table tbody tr').each(function() {
            const subject = $(this).find('td:eq(1)').text();
            const grade = $(this).find('td:eq(2)').text();
            const year = $(this).find('td:eq(3)').text().replace('年', '');
            
            const showSubject = currentFilters.subject === 'all' || subject === currentFilters.subject;
            const showGrade = currentFilters.grade === 'all' || grade === currentFilters.grade;
            const showYear = currentFilters.year === 'all' || year === currentFilters.year;
            
            if (showSubject && showGrade && showYear) {
                $(this).show();
            } else {
                $(this).hide();
            }
        });
    }
    
    // 学科分类筛选
    $('.list-group-item[data-subject]').click(function(e) {
        e.preventDefault();
        $('.list-group-item[data-subject]').removeClass('active');
        $(this).addClass('active');
        currentFilters.subject = $(this).data('subject');
        updateFileList();
    });
    
    // 年份筛选
    $('#yearFilter').change(function() {
        currentFilters.year = $(this).val();
        updateFileList();
    });
    
    // 年级筛选
    $('#gradeFilter').change(function() {
        currentFilters.grade = $(this).val();
        updateFileList();
    });
    
    // 初始化：选中"全部"选项
    $('.list-group-item[data-subject="all"]').addClass('active');
    $('#yearFilter').val('all');
    $('#gradeFilter').val('all');
}); 